package com.nowcoder.community.community.dao;

import com.nowcoder.community.community.entity.LoginTicket;
import org.apache.ibatis.annotations.*;

@Mapper
@Deprecated// 声明此主键不推荐使用
public interface LoginTicketMapper {

    @Insert({
            "insert into login_ticket(user_id,ticket,status,expired) ",//习惯在每个""最后加上空格，防止拼接字符串时出错
            "values(#{userId},#{ticket},#{status},#{expired})"
    })
    @Options(useGeneratedKeys = true,keyProperty = "id")//定义主键
    int insertLoginTicket(LoginTicket loginTicket);

    @Select({
            "select id,user_id,ticket,status,expired ",
            "from login_ticket where ticket=#{ticket}"
    })
    LoginTicket selectByTicket(String ticket);

    @Update({
            "<script> ",//如果使用<if>条件，则需要在最外层加上<script></script>，表示脚本
            "update login_ticket set status=#{status} where ticket=#{ticket} ",
            "<if test=\"ticket!=null\"> ",
            "and 1=1 ",
            "</if> ",
            "</script> "
    })
    int updateStatus(String ticket,int status);

}
